<script setup lang="ts">
import {onBeforeUnmount, onMounted, ref} from "vue";
import {useRouter,useRoute} from "vue-router";
import type { ComponentSize } from 'element-plus'
import {
  getcatelist,
  getprodcolorinfo, getsmprodcategorylist, prodinfo
} from "@/axios/api.js"
const router = useRouter();
const  route = useRoute()
let colorList = ref([])
const size = ref<ComponentSize>('large')
const background = ref(true)//背景颜色
const disabled = ref(false)//选择
let pagerCount = ref(0)
let innerWidth= ref(0)
let layout = ref(" prev, next")
let color = ref("")
let getcatelistVal = ref([])
color.value = route.query.name
let froms = ref({
  page:1,
  pagesize:20,
  pid:"",
  total:1
})

froms.value.pid = route.query.id
const handleTo = (item:any) => {
  router.push({path:"/particulars",query:{id:item.id,name:item.category_name,title:color.value}})
}
//颜色
const getprodcolorinfos = () => {
  getprodcolorinfo().then((res: any) => {
    colorList.value = res.data.list
  })
}
getprodcolorinfos()

const updateWidth = () => {
  innerWidth.value = window.innerWidth;
  if(innerWidth.value<600){
    size.value = "small"
    layout.value = "prev, next"
  }
};
const handleNumsTab = (item:any) => {
  froms.value.pid = item.id
  color.value = item.category_name
  froms.value.page = 1
  getcatelistVal.value = []
  getcatelists()
}
const getcatelists = () => {
  getsmprodcategorylist(froms.value).then((res:any) => {
    pagerCount.value= res.data.list.last_page
    getcatelistVal.value = [...getcatelistVal.value,...res.data.list.data]
    froms.value.total = res.data.list.total
  })
}
const checkIfBottom = () => {
  const scrollPosition = window.scrollY + window.innerHeight;
  const pageHeight = document.documentElement.scrollHeight;
  if(scrollPosition >= pageHeight){
      if(froms.value.page<pagerCount.value){
        froms.value.page += 1
        getcatelists()
      }
  }
  // isBottom.value = scrollPosition >= pageHeight;
};
getcatelists()
onMounted(() => {
  innerWidth.value = window.innerWidth;
  if(innerWidth.value<600){
    size.value = "small"
    layout.value = "prev, next"
  }
  window.addEventListener('resize', updateWidth);
  window.addEventListener('scroll', checkIfBottom);
})
onBeforeUnmount(() => {
  window.removeEventListener('resize', updateWidth);
  window.removeEventListener('scroll', checkIfBottom);
});
</script>

<template>
  <div class="exhibition reveal-top">
    <div class="exhibition-tltle Color_ffffff Flex Flex_A_C Flex_J_Sb">
      <div class="exhibition-tltle-l">
        <div class="Font_size28 fontFamilyR Color_ffffff07">
          <span>Stone material</span>
        </div>
        <div class="Font_size28 fontFamilyR">
          <span>{{ color }}</span>
        </div>
      </div>
      <div class="exhibition-tltle-r  Flex">
        <div class="exhibition-tltle-r-item  Font_size17"
             :class="color==a.category_name?'Color_DE0E35':''"
             @click="handleNumsTab(a)"
             v-for="(a) in colorList" :key="a.id">
          <div class="Hover_scale">
            <span>{{ a.category_name }}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="exhibition-center Color_ffffff Margin_T60 reveal-top ">
      <div class="exhibition-center-item  " v-for="(a) in getcatelistVal" @click="handleTo(a)" :key="a.id">
        <div class="exhibition-center-item-1 Hover_scale">
          <img :src="a.image" alt="暂无图片">
        </div>
        <div class="Font_size23 Margin_T30 fontFamilyR Text_align">
          <span>
            {{ a.category_name }}
          </span>
        </div>
      </div>
    </div>
  </div>

</template>

<style scoped>
.exhibition {
  padding: 106px 163px;
  background-color: RGBA(35, 37, 40, 1);
  background-image: url("@/assets/img/stone.png");
  background-size: 100% 890px;
  background-repeat: no-repeat;
.exhibition-center{
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 30px;
}
  .exhibition-center-item {
    .exhibition-center-item-1{
      width: 370px;
      height: 244px;
      position: relative;
    }

  }

  .exhibition-tltle-r-item {
    padding: 0 25px;
    border-right: 1px solid RGBA(139, 140, 141, 1);
    position: relative;
    z-index: 1100;

    &:last-child {
      border-right: none;
    }
  }
}
.fenye{
  display: flex;
  justify-content: right;
  margin-top: 60px;
}
@media screen and (max-width: 600px){
  .exhibition {
    padding: 106px 163px;
    background-color: RGBA(35, 37, 40, 1);
    background-image: url("@/assets/img/stone.png");
    background-size: 100% 890px;
    background-repeat: no-repeat;
    .exhibition-center{
      display: grid;
      grid-template-columns: repeat(2,1fr);
      gap: 80px;
    }
    .exhibition-center-item {
      .exhibition-center-item-1{
        width:95%;
        height: 444px;
        position: relative;
      }
    }

    .exhibition-tltle-r-item {
      padding: 0 25px;
      border-right: 1px solid RGBA(139, 140, 141, 1);
      position: relative;
      z-index: 1100;

      &:last-child {
        border-right: none;
      }
    }
  }
}
</style>